﻿using System;
using COUP.Core.Enums;

namespace COUP.Core.Networking
{
    public unsafe class NewCharacterPacket : Packet
    {
        public NewCharacterPacket(Packet Data)
        {
            buffer = Data.Buffer;
        }

        public string Name
        {
            get
            {
                fixed (byte* lpbuffer = buffer)
                    return new string((char*)lpbuffer, 4, 16).TrimEnd('\0');
            }
        }

        public string Password
        {
            get
            {
                fixed (byte* lpbuffer = buffer)
                    return new string((char*)lpbuffer, 20, 16).TrimEnd('\0');
            }
        }

        public string Server
        {
            get
            {
                fixed (byte* lpbuffer = buffer)
                    return new string((char*)lpbuffer, 36, 16).TrimEnd('\0');
            }
        }

        public ushort ModelID
        {
            get
            {
                fixed (byte* lpbuffer = buffer)
                    return *((ushort*)(lpbuffer + 52));
            }
        }

        public byte Job
        {
            get
            {
                fixed (byte* lpbuffer = buffer)
                    return *((byte*)(lpbuffer + 54));
            }
        }

        public int AccountID
        {
            get
            {
                fixed (byte* lpbuffer = buffer)
                    return *((int*)(lpbuffer + 56));
            }
        }

        public byte Avatar
        {
            get
            {
                if (ModelID <= 1004)
                    return 1;
                else
                    return 201;
            }
        }
    }
}
